<template>
  <div>
    <a-card :bordered="false">
      <van-search placeholder="请选择条件查询" readonly @click="showSearchPopup" style="margin-top: -10px;width: 100%;padding: 0px;margin-bottom: 10px"/>
      <!-- table区域-begin -->
      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoadList"
        >

          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
            @click="inspectionDetail(item)">
            <div>
              <div class="name" v-if="item.ghCustomerInfo">{{item.ghCustomerInfo.name}}</div>
              <div class="contact">
                <span v-if="item.ghCustomerInfo">电话：{{ item.ghCustomerInfo.phone || '无' }}</span>
                <span style="margin-left: 10px;" v-if="item.ghCustomerInfo">地址：{{ item.ghCustomerInfo.address || '无'}}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>
      <van-popup v-model="showSearchPopupFlag" position="top" >
        <a-card :bordered="false">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <div>添加时间：
              <a-input @click="createTime.show = true" v-model="createTime.text" readOnly style="text-align: center"></a-input>
              <van-popup v-model="createTime.show" round position="bottom">
                <van-picker
                  show-toolbar
                  title="请选择时间"
                  :columns="addDateList"
                  value-key="itemText"
                  @cancel="createTime.show = false"
                  @confirm="changeCreateTime" />
              </van-popup>
            </div>
            <div style="margin-top: 5px">创建人：
              <van-dropdown-menu>
                <van-dropdown-item v-model="value2" :options="userOption" @change="changeCreateBy"/>
              </van-dropdown-menu>
            </div>
            <a-row :gutter="24" style="margin-bottom: 10px;margin-top: 10px">
              <a-col :span="12">
                <a-button type="primary" style="width: 100%" @click="searchQuery" icon="search">查询</a-button>
              </a-col>
              <a-col :span="12">
                <a-button type="primary" @click="searchReset" icon="reload" style="width: 100%">重置</a-button>
              </a-col>
            </a-row>
          </a-form>
        </a-card>
      </van-popup>

      <inspection-detail-modal ref="inspectionDetailModal"></inspection-detail-modal>
    </a-card>
  </div>
</template>

<script>

  import '@assets/less/TableExpand.less'
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {filterDictTextByCache} from '@comp/dict/JDictSelectUtil'
  import {getAction} from "../../../../api/manage";
  import {filterObj} from '@/utils/util';
  import inspectionDetailModal from "./modules/inspectionDetailModal";

  export default {
    name: 'inspectionManageList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      inspectionDetailModal,
    },
    data() {
      return {
        createBy: "",
        addDateList: [],
        value1:[],
        description: '巡查管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '姓名',
            align: "center",
            dataIndex: 'ghCustomerInfo.name',
            scopedSlots: { customRender: 'name' },
          },
          {
            title: '项目地址',
            align: "center",
            dataIndex: 'ghCustomerInfo.address'
          },
          {
            title: '巡检时间',
            align: "center",
            dataIndex: 'circuitTime'
          },
          {
            title: '巡检情况',
            align: "center",
            dataIndex: 'situation',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '700px',
                }
              }
            }
          },
          {
            title: '业主反馈',
            align: "center",
            dataIndex: 'feedback',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '700px',
                }
              }
            }
          },
          {
            title: '添加人',
            align: "center",
            dataIndex: 'createBy'
          },
          {
            title: '添加时间',
            align: "center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {customRender: 'action'}
          }
        ],
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        /* 数据源 */
        dataSource: [],
        createByData:[],    //创建人列表
        currentDateValue: '',
        currentKey: false,
        startDate:'',
        endDate:'',
        url: {
          list: "/ghSiteCircuit/inspectionManageList",
          delete: "/ghSiteCircuit/delete",
          getSearchConditionData: "/ghSiteCircuit/getQueryCriteriaData",
          queryUserList: "/erp/user/selectUserByDepartId",
          queryDepartTreeList: "/erp/user/selectDepartTreeList",
        },
        dictOptions: {},
        dataFields: {
          title: 'departName',
          key: 'id',
          value: 'id',
          children: "children"
        },
        currentDepartId: "",  //当前所选部门
        departListData:[],    //部门列表
        createTime:{
          show:false,
          text:'全部',
        },
        finished: false,
        loading: false,
        showSearchPopupFlag: false,
        value2: "",
        userOption: [
          {text:'全部',value:""}
        ],
      }
    },
    created() {
      //this.loadData();
      this.loadUserListData();
      this.initSearchData();
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showSearchPopup(){
        this.showSearchPopupFlag = true
      },
      searchQuery(){
        this.loadData(1);
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
      },
      searchReset() {
        this.currentDateValue = ""
        this.createTime.text = "全部"
        this.value2 = ""
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
        this.loadData(1);
      },
      circuitDetail(record){
        let key = 12;
        this.$router.push({ path: "/infoTab", query: {id: record.customerId, name: record.ghCustomerInfo.name, key: "12"}});
      },
      //加载用户列表
      loadUserListData() {
        getAction(this.url.queryUserList).then((res) => {
          if (res.success) {
            this.createByData = res.result.records||res.result;
            for (let i=0;i<this.createByData.length;i++){
              this.userOption.push({
                text: this.createByData[i].realname,
                value: this.createByData[i].realname
              })
            }
          }
        })
      },
      filterOptionCreateBy(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      changeCreateBy(value){
        this.showSearchPopupFlag = false
        this.queryParam.createBy = value
        this.loadData(1);
      },
      initSearchData() {
        getAction(this.url.getSearchConditionData).then(res => {
          if (res.success) {
            let addDateList = res.result.circuitDateList;
            addDateList = addDateList.filter((item) => item.itemValue !== "customizeTime");
            this.addDateList = addDateList;
          }
        })
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = [];
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;

        if (this.currentDateValue != null && this.currentDateValue != '') {
          params.currentTime = this.currentDateValue;
          if (this.currentDateValue == "customizeTime"){
            params.beginTime = this.startDate;
            params.endTime = this.endDate;
          }
        }
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
            if(res.result.records.length<10){
              this.finished = true;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      inspectionDetail(record){
        //inspectionDetailModal
        this.$refs.inspectionDetailModal.showDrawer(record);
        this.$refs.inspectionDetailModal.title = "巡查信息";
      },
      changeCreateTime(e){
        this.createTime.text = e.itemText
        this.createTime.show = false
        const { key, itemValue, itemText } = e
        this.currentDateValue = itemValue
        let obj = {
          key,
          itemValue,
          itemText
        }
        this.showSearchPopupFlag = false
        this.loadData(1)
      },
      //下一页
      onLoadList(){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
  /deep/ .van-dropdown-menu__bar{
    height: 30px;
    box-shadow: none;
    border: 1px solid lightgrey;
    border-radius: 5px;
  }
  .select-pk{
    display:flex;
    align-items:center;
    margin:10px 0;
    &>span{
      font-weight: bold;
    }
    &-text{
      width: calc(100% - 6em);
      height: 30px;
      text-indent: 1em;
      line-height: 28px;
      border: 1px solid #d9d9d9;
      border-radius: 4px;
    }
  }
  .list{
    overflow-y: scroll;
    height:100vh;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list{
    display: flex;
    align-items: center;
    border-top: 1px solid #d9d9d9;
    height: 70px;
    .name{
      font-size: 13px;
      color: #161616;
      line-height: normal;
    }
    .contact{
      font-size: 12px;
      color: #a39f9f;
    }
  }
</style>